package cn.stylefeng.guns.modular.tool.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.tool.entity.ToolExpressReconciliationRf;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressReconciliationRfParam;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressReconciliationYzParam;
import cn.stylefeng.guns.modular.tool.service.ToolExpressReconciliationRfService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.guns.sys.modular.system.service.UserService;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 软风对账管理控制器
 *
 * @author zhucx
 * @Date 2022-12-27 17:25:15
 */
@Controller
@RequestMapping("/toolExpressReconciliationRf")
public class ToolExpressReconciliationRfController extends BaseController {

    private String PREFIX = "/toolExpressReconciliationRf";

    @Autowired
    private ToolExpressReconciliationRfService toolExpressReconciliationRfService;

    @Autowired
    private UserService userService;

    /**
     * 跳转到主页面
     *
     * @author zhucx
     * @Date 2022-12-27
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/toolExpressReconciliationRf.html";
    }

    /**
     * 新增页面
     *
     * @author zhucx
     * @Date 2022-12-27
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/toolExpressReconciliationRf_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zhucx
     * @Date 2022-12-27
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/toolExpressReconciliationRf_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zhucx
     * @Date 2022-12-27
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ToolExpressReconciliationRfParam toolExpressReconciliationRfParam) {
        this.toolExpressReconciliationRfService.add(toolExpressReconciliationRfParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zhucx
     * @Date 2022-12-27
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ToolExpressReconciliationRfParam toolExpressReconciliationRfParam) {
        this.toolExpressReconciliationRfService.update(toolExpressReconciliationRfParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zhucx
     * @Date 2022-12-27
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ToolExpressReconciliationRfParam toolExpressReconciliationRfParam) {
        this.toolExpressReconciliationRfService.delete(toolExpressReconciliationRfParam);
        return ResponseData.success();
    }

    /**
     * 清空接口
     *
     * @author zhucx
     * @Date 2022-12-14
     */
    @RequestMapping("/btnRevoke2")
    @ResponseBody
    public ResponseData btnRevoke2(ToolExpressReconciliationRfParam toolExpressReconciliationRfParam) {
		this.toolExpressReconciliationRfService.deleteBySpec(toolExpressReconciliationRfParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zhucx
     * @Date 2022-12-14
     */
    @RequestMapping("/btnDelete2")
    @ResponseBody
    public ResponseData btnDelete2(Integer[] ids) {
    	for (Integer id : ids) {
    		ToolExpressReconciliationRfParam toolExpressReconciliationRfParam = new ToolExpressReconciliationRfParam();
    		toolExpressReconciliationRfParam.setId(id);
    		this.toolExpressReconciliationRfService.delete(toolExpressReconciliationRfParam);
		}
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zhucx
     * @Date 2022-12-27
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ToolExpressReconciliationRfParam toolExpressReconciliationRfParam) {
        ToolExpressReconciliationRf detail = this.toolExpressReconciliationRfService.getById(toolExpressReconciliationRfParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zhucx
     * @Date 2022-12-27
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ToolExpressReconciliationRfParam toolExpressReconciliationRfParam,String condition ) {
        return this.toolExpressReconciliationRfService.findPageBySpec(toolExpressReconciliationRfParam,condition);
    }
    
    /**
     * 导出软风核对账单Excel
     */
    @RequestMapping("/exportToExcel")
    public void exportToExcel(HttpServletResponse response,Long reconciliationId,String v1) throws IOException {
        Workbook wb = toolExpressReconciliationRfService.exportToExcel(reconciliationId,v1);
        OutputStream output = response.getOutputStream();
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + new String(("极鹿收入核对账单" + ".xlsx").getBytes(), "iso-8859-1"));
        wb.write(output);
        output.close();
    }

}


